package com.et114.modules.org.cells;

import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.extremecomponents.table.bean.Column;
import org.extremecomponents.table.cell.Cell;
import org.extremecomponents.table.core.TableModel;
//import org.extremecomponents.table.limit.Limit;
//import org.extremecomponents.table.limit.Sort;
import org.extremecomponents.util.HtmlBuilder;

import com.et114.components.ectable.EXTableUtils;

/**
 * 
 * @author guanhw
 *
 */
public class FuncAttachModifyHrefCell  implements Cell {
	protected  Log logger = LogFactory.getLog( this.getClass ( ) );

	public String getExportDisplay ( TableModel arg0 , Column arg1 ) {
		// TODO Auto-generated method stub
		return null;
	}

	public String getHtmlDisplay ( TableModel model , Column arg1 ) {
		HtmlBuilder html = new HtmlBuilder();
		html.td ( 0 ).xclose ( ) ;
		try {
			/*
			Limit limit = model.getLimit ( );
			int curPage = limit.getPage();
			params.append ( "&ec_p=" ).append ( curPage ) ; 
			*/
			String tableId = model.getTableHandler ( ).getTable ( ).getTableId ( ) ;
			String params = EXTableUtils.getLimitParams ( tableId , model.getLimit ( ) ) ;
			/*
			Sort sort = limit.getSort ( );
			if ( sort.getProperty ( ) != null ) {
				params.append ( "&" ).append ( "ec_s_" + sort.getProperty ( ) );
				params.append ( "=" ).append ( sort.getSortOrder ( ) ) ;
			}
			*/
			Object bean = model.getCurrentRowBean();
            
            
			String id = BeanUtils.getProperty( bean, "id" ); //model.getLimit ( ).getSort ( ).getProperty ( )
			String url = model.getContext().getContextPath() + "/funcAttach.go?method=loadAttach&id=" + id + params ;
			html.a( "javascript:location='" + url + "'" );
			html.xclose ( );
			html.img ( model.getContext().getContextPath() + "/themes/styles/default/images/edit.gif" ) ; 
			html.aEnd ( );
		} catch (Exception e) {
			logger.error ( e.getMessage ( ) , e ) ;
		}
		html.tdEnd ( );
		return html.toString();	
	}
	
}
